<?php
session_start(); 
include "application.php";
include "common.php";
application_start();
//print_r($_POST);

//Option Explicit;

//dim $strChatName,$strNewChatName,$strChatInput,$strChatBody,$strUsers;
//dim intChatBodyLength, $intFrameHeight, $intChatTimeout;
//dim $strFont,$strColor,$strSize;
//dim $strLogin, $strLogout, $strUserConflict, $strNewNick;
 
// ********* User-alterable parameters *******************************
 
// Set the maximum size of the chat content; anything beyond this will be 
//  trimmed after the curent line is added.
$intChatBodyLength = 3000;
 
// Set the height of the "Who's Here" frame (IE only); this is useful
//  if you are using Portachat in a different-sized window.
$intFrameHeight = 200;
 
// Set the timeout value; users will be logged out if they are idle for 
//   this amount of time (set in minutes)
$intChatTimeout = 20;
 
// ************************************************************
 

if (strpos(strtolower($_SERVER["HTTP_REFERER"]),"menu.php") > 1) {
//	$strChatName = Server.$HTMLEncode[trim(@$_POST["ChatName"])];
	$strChatName = @$_POST["ChatName"];
} else {
//	$strChatName = Server.$HTMLEncode[trim(Request.$Cookies["ChatName"])];
	$strChatName = @$_POST["ChatName"];
}

//$strChatInput = Server.$HTMLEncode[@$_POST["ChatInput"]];
if(@$_POST["chatInput"] != ""){
	$strChatInput = @$_POST["chatInput"];	
}else{
	$strChatInput = @$_POST["ChatInput"];
}
$strLogin = @$_POST["login"];
 
//$strColor = str_replace(";","",Server.$HTMLEncode[@$_POST["Color"]]);
//$strFont = str_replace(";","",Server.$HTMLEncode[@$_POST["Font"]]);
//$strSize = str_replace(";","",Server.$HTMLEncode[@$_POST["Size"]]);
$strColor = str_replace(";","",@$_POST["Color"]);
$strFont = str_replace(";","",@$_POST["Font"]);
$strSize = str_replace(";","",@$_POST["Size"]);


//$strChatBody = Application("strChatBody"); // This one Application variable is the key.
//$strUsers = Application("strUsers");
//print_r($strChatInput);
$strChatBody = $_APP["strChatBody"];
$strUsers = $_APP["strUsers"];

include "processinput.php";

 
if ($strUserConflict != "true") {
	if (strlen($strChatBody) > intChatBodyLength) { // Keeps the variable at a manageable length
		//$strChatBody = right($strChatBody,intChatBodyLength);
		//$strChatBody = mid($strChatBody,instr($strChatBody,"</B>")+4,strlen($strChatBody));
	}
 
	
//	Application.Lock();
//	Application("strChatBody") = $strChatBody;
//	Application("strUsers") = $strUsers;
//	Application.Unlock();  $_APP["strChatBody"] . 
	$_APP["strChatBody"] = $strChatBody;
	$_APP["strUsers"] = $strUsers;		
	
	application_end ();
	
} elseif ($strLogin == "true"){
	header("Location: blank.php?conflict=true");
}
?>
<HTML>
<HEAD>
	<TITLE>Chat Room</TITLE>
<? include "style.php"; ?>
<SCRIPT LANGUAGE="JavaScript">
function initialize() 
{
	if(parent.location.href != window.location.href) {
		document.mainForm.chatInput.focus();
<?if (strtolower(@$_POST["login"]) > " sign on ") {?>
		top.bodyFrame.location.replace('body.php?chatTimeout=<? echo $intChatTimeout?>');
		top.menuFrame.location.replace('chatmenu.php?chatname=<?=Server.$URLEncode[$strChatName]?>&frameheight=<? echo $intFrameHeight?>');
<?} elseif ($strLogout == "true"){ ?>

		top.bodyFrame.location.replace('welcome.php');
		top.menuFrame.document.mainForm.logout.value = "true";
		top.menuFrame.location.replace('menu.php');
		window.location.replace('blank.php');
<?} elseif ($strUserConflict == "true"){ ?>
		alert("The name you chose is invalid or currently in use.\nPlease choose another.");
<?} else {?>
		top.bodyFrame.location.reload();
<?}?>

<?if ($strNewNick == "true") {?>
		if(document.all) {
			top.menuFrame.document.all.chatNameDiv.innerHTML = "<B><? echo $strChatName?></B>";
		}
<?}?>
	}
	else {
		window.location.replace("bye.php");
//		self.close();
		}
	}

function checkUsers(pageName) {
	var checkWin = window.open(pageName,"checkUsers","height=250,width=150,toolbars=no,scrollbars=yes,resizable=no");
	}
</SCRIPT>
</HEAD>

<BODY BGCOLOR="<? echo $strFrameColor; ?>" onLoad="initialize()">
<?
//Response.Write Request.ServerVariables("HTTP_REFERER")
//echo "strChatName: " . $strChatName . "<BR>";
//echo "strNewChatName: " . $strNewChatName . "<BR>";
//echo "strUsers: " . $strUsers . "<BR>";
 
?>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=2 HEIGHT="100%" WIDTH="100%">
<TR><TD VALIGN="TOP">
<FORM NAME="mainForm" ACTION="<? echo $_SERVER["PHP_SELF"]?>" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="ChatName" VALUE="<? echo $strChatName; ?>">
<INPUT TYPE="HIDDEN" NAME="Font" VALUE="<? echo $strFont; ?>">
<INPUT TYPE="HIDDEN" NAME="Color" VALUE="<? echo $strColor; ?>">
<INPUT TYPE="HIDDEN" NAME="Size" VALUE="<? echo $strSize; ?>">
<INPUT TYPE="HIDDEN" NAME="Logout">
<INPUT TYPE="TEXT" NAME="chatInput" SIZE=30><BR>
<INPUT TYPE="SUBMIT" NAME="chatSubmit" VALUE=" Send ">
<INPUT TYPE="SUBMIT" NAME="chatSubmit" VALUE="Log out">
<!--<INPUT TYPE="BUTTON" NAME="Who" VALUE="See who's on" onClick="checkUsers('checkusers.php')">-->
</FORM>
</TD>
<TD ALIGN="RIGHT"> &nbsp;

</TD></TR></TABLE>
</BODY>
</HTML>
